from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-04-20 14:10:56.727287
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Tue, 20, Apr, 2021
Time: 14:11:01
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.6477
Nobs: 267.000 HQIC: -48.3712
Log likelihood: 3202.68 FPE: 6.05151e-22
AIC: -48.8569 Det(Omega_mle): 4.34657e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.436617 0.123131 3.546 0.000
L1.Burgenland 0.082526 0.060991 1.353 0.176
L1.Kärnten -0.220861 0.053611 -4.120 0.000
L1.Niederösterreich 0.085859 0.131844 0.651 0.515
L1.Oberösterreich 0.213429 0.125725 1.698 0.090
L1.Salzburg 0.269766 0.069702 3.870 0.000
L1.Steiermark 0.118344 0.088683 1.334 0.182
L1.Tirol 0.120343 0.061045 1.971 0.049
L1.Vorarlberg -0.035106 0.056212 -0.625 0.532
L1.Wien -0.060756 0.113862 -0.534 0.594
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.481822 0.143303 3.362 0.001
L1.Burgenland 0.002551 0.070982 0.036 0.971
L1.Kärnten 0.328243 0.062393 5.261 0.000
L1.Niederösterreich 0.071011 0.153443 0.463 0.644
L1.Oberösterreich -0.061480 0.146321 -0.420 0.674
L1.Salzburg 0.222920 0.081121 2.748 0.006
L1.Steiermark 0.103592 0.103211 1.004 0.316
L1.Tirol 0.142158 0.071045 2.001 0.045
L1.Vorarlberg 0.155607 0.065421 2.379 0.017
L1.Wien -0.434555 0.132515 -3.279 0.001
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.283438 0.062207 4.556 0.000
L1.Burgenland 0.096034 0.030813 3.117 0.002
L1.Kärnten -0.016622 0.027084 -0.614 0.539
L1.Niederösterreich 0.068074 0.066608 1.022 0.307
L1.Oberösterreich 0.284085 0.063517 4.473 0.000
L1.Salzburg 0.023532 0.035214 0.668 0.504
L1.Steiermark -0.002096 0.044803 -0.047 0.963
L1.Tirol 0.072582 0.030840 2.353 0.019
L1.Vorarlberg 0.082028 0.028399 2.888 0.004
L1.Wien 0.112504 0.057524 1.956 0.050
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.217868 0.060008 3.631 0.000
L1.Burgenland 0.022936 0.029724 0.772 0.440
L1.Kärnten 0.008690 0.026127 0.333 0.739
L1.Niederösterreich 0.052043 0.064254 0.810 0.418
L1.Oberösterreich 0.400453 0.061272 6.536 0.000
L1.Salzburg 0.082691 0.033969 2.434 0.015
L1.Steiermark 0.127502 0.043220 2.950 0.003
L1.Tirol 0.050739 0.029750 1.706 0.088
L1.Vorarlberg 0.083289 0.027395 3.040 0.002
L1.Wien -0.046143 0.055490 -0.832 0.406
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.500049 0.117261 4.264 0.000
L1.Burgenland 0.092434 0.058083 1.591 0.112
L1.Kärnten 0.009851 0.051055 0.193 0.847
L1.Niederösterreich -0.004585 0.125559 -0.037 0.971
L1.Oberösterreich 0.132934 0.119732 1.110 0.267
L1.Salzburg 0.061972 0.066379 0.934 0.351
L1.Steiermark 0.062351 0.084456 0.738 0.460
L1.Tirol 0.212864 0.058135 3.662 0.000
L1.Vorarlberg 0.033481 0.053533 0.625 0.532
L1.Wien -0.093698 0.108434 -0.864 0.388
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.194987 0.093128 2.094 0.036
L1.Burgenland -0.011300 0.046129 -0.245 0.806
L1.Kärnten -0.007495 0.040548 -0.185 0.853
L1.Niederösterreich -0.000866 0.099718 -0.009 0.993
L1.Oberösterreich 0.412218 0.095090 4.335 0.000
L1.Salzburg 0.015967 0.052718 0.303 0.762
L1.Steiermark -0.031892 0.067074 -0.475 0.634
L1.Tirol 0.160110 0.046170 3.468 0.001
L1.Vorarlberg 0.055919 0.042515 1.315 0.188
L1.Wien 0.217485 0.086118 2.525 0.012
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.242997 0.112752 2.155 0.031
L1.Burgenland 0.016129 0.055850 0.289 0.773
L1.Kärnten -0.072427 0.049092 -1.475 0.140
L1.Niederösterreich -0.087807 0.120731 -0.727 0.467
L1.Oberösterreich 0.026959 0.115128 0.234 0.815
L1.Salzburg 0.084510 0.063827 1.324 0.185
L1.Steiermark 0.332772 0.081208 4.098 0.000
L1.Tirol 0.463346 0.055899 8.289 0.000
L1.Vorarlberg 0.149785 0.051474 2.910 0.004
L1.Wien -0.151707 0.104264 -1.455 0.146
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.186036 0.134595 1.382 0.167
L1.Burgenland 0.039493 0.066669 0.592 0.554
L1.Kärnten -0.074326 0.058602 -1.268 0.205
L1.Niederösterreich 0.132487 0.144120 0.919 0.358
L1.Oberösterreich 0.017958 0.137431 0.131 0.896
L1.Salzburg 0.201194 0.076192 2.641 0.008
L1.Steiermark 0.115494 0.096940 1.191 0.233
L1.Tirol 0.059232 0.066728 0.888 0.375
L1.Vorarlberg 0.101449 0.061446 1.651 0.099
L1.Wien 0.227570 0.124463 1.828 0.067
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.554908 0.073290 7.571 0.000
L1.Burgenland -0.020764 0.036303 -0.572 0.567
L1.Kärnten -0.020175 0.031910 -0.632 0.527
L1.Niederösterreich 0.069796 0.078476 0.889 0.374
L1.Oberösterreich 0.306594 0.074834 4.097 0.000
L1.Salzburg 0.021522 0.041488 0.519 0.604
L1.Steiermark -0.039100 0.052786 -0.741 0.459
L1.Tirol 0.083969 0.036335 2.311 0.021
L1.Vorarlberg 0.109313 0.033459 3.267 0.001
L1.Wien -0.060337 0.067773 -0.890 0.373
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.151317 0.090241 0.166208 0.220429 0.078902 0.083444 0.009498 0.154233
Kärnten 0.151317 1.000000 0.044512 0.205632 0.179739 -0.060048 0.166256 0.026144 0.299963
Niederösterreich 0.090241 0.044512 1.000000 0.238088 0.077861 0.329546 0.140716 0.025814 0.294647
Oberösterreich 0.166208 0.205632 0.238088 1.000000 0.300609 0.263388 0.089693 0.061168 0.131044
Salzburg 0.220429 0.179739 0.077861 0.300609 1.000000 0.155890 0.054987 0.089150 0.009940
Steiermark 0.078902 -0.060048 0.329546 0.263388 0.155890 1.000000 0.102823 0.096476 -0.101262
Tirol 0.083444 0.166256 0.140716 0.089693 0.054987 0.102823 1.000000 0.159260 0.143388
Vorarlberg 0.009498 0.026144 0.025814 0.061168 0.089150 0.096476 0.159260 1.000000 -0.007043
Wien 0.154233 0.299963 0.294647 0.131044 0.009940 -0.101262 0.143388 -0.007043 1.000000